//
//  MonitorSelectViewController.m
//  Light
//
//  Created by 石雄伟 on 15/12/19.
//  Copyright © 2015年 骁唐. All rights reserved.
//

#import "MonitorSelectViewController.h"
#import "MonitorRealTimeViewController.h"

@interface MonitorSelectViewController ()
//背景图片
@property (weak, nonatomic) IBOutlet UIImageView *backGround;
//心电按钮
@property (weak,nonatomic) IBOutlet UIButton * buttonHeart;
//脑电按钮
@property (weak,nonatomic) IBOutlet UIButton * buttonHead;

@end

@implementation MonitorSelectViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    delegate.isAtHeart = YES;//处于心电界面
    delegate.scope = -100;
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
    CGRect frame = [UIScreen mainScreen].applicationFrame;
    self.view.bounds = CGRectMake(0, 0, frame.size.height, frame.size.width);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configUI];//配置返回按钮
    [[UIApplication sharedApplication] setIdleTimerDisabled: YES];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}

#pragma mark -
#pragma mark 状态栏样式
- (UIStatusBarStyle)preferredStatusBarStyle
{
    //白色
    return UIStatusBarStyleLightContent;
}

#pragma mark -
#pragma mark 隐藏状态栏
- (BOOL)prefersStatusBarHidden
{
    return YES;
}


#pragma mark -
#pragma mark 配置返回按钮
- (void)configUI
{
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(25,15, 60, 30)];

    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 20, 20)];
    backImage.image = [UIImage imageNamed:@"left"];
    
    
    UILabel *backlLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 40, 30)];
    backlLabel.text = @"返回";
    backlLabel.textColor = [UIColor whiteColor];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 140)];
    [backBtn addTarget:self action:@selector(backClickB) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backClickB)];
    [backView addGestureRecognizer:click];
    [backView addSubview:backImage];
    [backView addSubview:backlLabel];
    [backView addSubview:backBtn];
    
    backView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:backView];
}

#pragma mark -
#pragma mark 返回上级界面
-(void) backClickB
{
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    delegate.isAtHeart = NO;
    if (delegate.peripheral != nil) {
        Byte ACkValue[4] = {0};
        ACkValue[0] = 0xAE; ACkValue[1] = 0x01; ACkValue[2] = 0x06; ACkValue[3] = 0xAA;
        NSData *data = [NSData dataWithBytes:&ACkValue length:sizeof(ACkValue)];
        if ([delegate.writeCharacteristic.UUID.UUIDString isEqual:@"FFF2"]) {
            [delegate.peripheral writeValue:data
                          forCharacteristic:delegate.writeCharacteristic
                                       type:CBCharacteristicWriteWithResponse];
        }
    }
    [delegate.MonitorAry removeAllObjects];//清空数据
    delegate.judgeMonitor = NO;
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:YES];
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)DidClickButtonSelectToShow:(UIButton *)button
{
    switch (button.tag)
    {
        case 220:
        {
            AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
            delegate.scope = 2500.0;
            delegate.currentColor = TJJMakeColorWithRGB(25, 155, 231);
            delegate.type = @"1";
            [self performSegueWithIdentifier:@"monitorRealTimeShowId" sender:nil];//显示界面
        }
            break;
        case 221:
        {
            AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
            delegate.scope = 20000.0;
            delegate.currentColor = [UIColor redColor];
            delegate.type = @"2";
            [self performSegueWithIdentifier:@"monitorRealTimeShowId" sender:nil];//显示界面
        }
            break;
        case 222:
        {
            AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
            delegate.scope = 15000.0;
            delegate.currentColor = TJJMakeColorWithRGB(214, 165, 37);
            delegate.type = @"3";
            [self performSegueWithIdentifier:@"monitorRealTimeShowId" sender:nil];
        }
            break;
        default:
            break;
    }
}

- (void)noti
{
    NSNotification * notificationUpdataDataOne =[NSNotification notificationWithName:_NOTIFICATION_UPDATE_MONITOR_UI object:nil userInfo:nil];
    [[NSNotificationCenter defaultCenter] postNotification:notificationUpdataDataOne];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
